import matplotlib.pyplot as plt
import pandas as pd

df = pd.read_excel('./data1/computer_1_old.xlsx')
df['salary'] = df['salary'].astype(str)#转换成字符串类型
def extract_salary(value):
    if"万/月" in value:
        if "-" in value:
            min1 = float(value[:value.find('-')])
            max1 = float(value[value.find('-')+1:value.find('万')])
            new = (min1 + max1) / 2 * 10000
            return int(new)
        else:
            new=float(value[:value.find('万')])
            return int(new)
    elif "元/月" in value:
        new=float(value[:value.find('元')])
        return int(new)
    elif "元/天" in value:
        new=float(value[:value.find('元')])*22
        return int(new)
    elif"面议" in value:
        return None
    else:
        return None

df['salary_new'] = df['salary'].apply(extract_salary)
df.to_excel('.\data1\computer_1_new.xlsx',sheet_name='sheet1')
print(df)
salary = df['salary_new'].value_counts()
print(salary)
plt.rcParams['font.sans-serif']=['KaiTi']
salary.plot(kind ='bar',color=['b','r','y'])
for x,y in enumerate(salary):
    plt.text(x,y,str(y),ha='center',fontsize=12)
plt.title("罗坛作业：工资分布",fontsize=16)
plt.xlabel('工资价格',fontsize=16)
plt.ylabel('数量', fontsize=16)
plt.tight_layout()
plt.show()






